﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.ServiceModel;

namespace BLL.SystemInformation
{
    [ServiceContract]
    class UC_TravellerInformation
    {
        //实例化数据层
        DAL.DALMethod myDAL = new DAL.DALMethod();
        //指示方法定义一个操作协定
        [OperationContract]
        ///查询所有旅客
        public DataSet SelectAllTravellerInformation()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "UserControl_Loaded_SelectAllTravellerInformation";
            //查询数据缓存
            return myDAL.QueryDataSet("UC_TravellerInformation", parm);
        }
        /// <summary>
        /// 查询证件类型
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectCertificateType()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "UserControl_Loaded_SelectCertificateType";
            //查询数据缓存
            return myDAL.QueryDataSet("UC_TravellerInformation", parm);
        }
        /// <summary>
        /// 查询旅客类型
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectPassengerType()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "UserControl_Loaded_SelectTravellerType";
            //查询数据缓存
            return myDAL.QueryDataSet("UC_TravellerInformation", parm);
        }
        /// <summary>
        /// 查询性别
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectGenderType()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "InsertTravellerInformation_Loaded_SelectGender";
            //查询数据缓存
            return myDAL.QueryDataSet("UC_TravellerInformation", parm);
        }
        /// <summary>
        /// 新增旅客信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public int InsertPassengerInformation(int as_CertificateTypeID, int as_PassengerTypeID, string userName
            , int as_GenderID, DateTime dateOfBirth, string theAge, string countryOrRegion,
                   string certificateNumber, string phoneNumber, string emergencyPhone, string userAddres, string emergencyAddress, string zipCode, DateTime registerDate)
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@as_CertificateTypeID",SqlDbType.Int),
                new SqlParameter("@as_PassengerTypeID",SqlDbType.Int),
                new SqlParameter("@userName",SqlDbType.VarChar),
                new SqlParameter("@as_GenderID",SqlDbType.Int),
                new SqlParameter("@dateOfBirth",SqlDbType.DateTime),
                new SqlParameter("@theAge",SqlDbType.VarChar),
                new SqlParameter("@countryOrRegion",SqlDbType.VarChar),
                new SqlParameter("@certificateNumber",SqlDbType.VarChar),
                new SqlParameter("@phoneNumber",SqlDbType.VarChar),
                new SqlParameter("@emergencyPhone",SqlDbType.VarChar),
                new SqlParameter("@userAddres",SqlDbType.VarChar),
                new SqlParameter("@emergencyAddress",SqlDbType.VarChar),
                new SqlParameter("@zipCode",SqlDbType.VarChar),
                new SqlParameter("@registerDate",SqlDbType.DateTime),
            };
            //给对象数组赋值
            parm[0].Value = "UserControl_Loaded_SelectTraveller";
            parm[1].Value = as_CertificateTypeID;
            parm[2].Value = as_PassengerTypeID;
            parm[3].Value = userName;
            parm[4].Value = as_GenderID;
            parm[5].Value = dateOfBirth;
            parm[6].Value = theAge;
            parm[7].Value = countryOrRegion;
            parm[8].Value = certificateNumber;
            parm[9].Value = phoneNumber;
            parm[10].Value = emergencyPhone;
            parm[11].Value = userAddres;
            parm[12].Value = emergencyAddress;
            parm[13].Value = zipCode;
            parm[14].Value = registerDate;

            //查询数据缓存
            return myDAL.UpdateData("UC_TravellerInformation", parm);
        }
        /// <summary>
        /// 修改旅客信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public int UpdatePassengerInformation(int as_CertificateTypeID, int as_PassengerTypeID, string userName
            , int as_GenderID, DateTime dateOfBirth, string theAge, string countryOrRegion,
                   string certificateNumber, string phoneNumber, string emergencyPhone, string userAddres, string emergencyAddress, string zipCode, DateTime registerDate,int travellerId)
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@as_CertificateTypeID",SqlDbType.Int),
                new SqlParameter("@as_PassengerTypeID",SqlDbType.Int),
                new SqlParameter("@userName",SqlDbType.VarChar),
                new SqlParameter("@as_GenderID",SqlDbType.Int),
                new SqlParameter("@dateOfBirth",SqlDbType.DateTime),
                new SqlParameter("@theAge",SqlDbType.VarChar),
                new SqlParameter("@countryOrRegion",SqlDbType.VarChar),
                new SqlParameter("@certificateNumber",SqlDbType.VarChar),
                new SqlParameter("@phoneNumber",SqlDbType.VarChar),
                new SqlParameter("@emergencyPhone",SqlDbType.VarChar),
                new SqlParameter("@userAddres",SqlDbType.VarChar),
                new SqlParameter("@emergencyAddress",SqlDbType.VarChar),
                new SqlParameter("@zipCode",SqlDbType.VarChar),
                new SqlParameter("@registerDate",SqlDbType.DateTime),
                new SqlParameter("@traveller_id",SqlDbType.Int)
            };
            //给对象数组赋值
            parm[0].Value = "btn_Affirm_Click_UpdateTraveller";
            parm[1].Value = as_CertificateTypeID;
            parm[2].Value = as_PassengerTypeID;
            parm[3].Value = userName;
            parm[4].Value = as_GenderID;
            parm[5].Value = dateOfBirth;
            parm[6].Value = theAge;
            parm[7].Value = countryOrRegion;
            parm[8].Value = certificateNumber;
            parm[9].Value = phoneNumber;
            parm[10].Value = emergencyPhone;
            parm[11].Value = userAddres;
            parm[12].Value = emergencyAddress;
            parm[13].Value = zipCode;
            parm[14].Value = registerDate;
            parm[15].Value = travellerId;
            //查询数据缓存
            return myDAL.UpdateData("UC_TravellerInformation", parm);
        }
        /// <summary>
        /// 删除旅客信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public int DeletePassengerInformation(int travellerId)
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@traveller_id",SqlDbType.Int)
            };
            //给对象数组赋值
            parm[0].Value = "btn_Delete_Click_DelectTraveller";
            parm[1].Value = travellerId;
            //查询数据缓存
            return myDAL.UpdateData("UC_TravellerInformation", parm);
        }
    }
}
